/*
 * SPDX-License-Identifier: GPL-2.0
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
 * Description:
 * Author: -
 * Create: 2021.4.19
 */

#include "ossl_knl.h"
#include "hiudk3.h"
#include "hiudk_internal.h"

void hiudk_dma_free_coherent_align(void *udkdev, struct hinic3_dma_addr_align *mem_align)
{
    void *dev_hdl = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return;
    }

    dev_hdl = GET_DEV_HDL_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->com_ops.hiudk_dma_free_coherent_align != NULL))) {
        return ops->com_ops.hiudk_dma_free_coherent_align(dev_hdl, mem_align);
    }

    pr_err("ops is NULL! \n");
    return;
}

EXPORT_SYMBOL(hiudk_dma_free_coherent_align);

int hiudk_dma_zalloc_coherent_align(void *udkdev, u64 size, u64 align, unsigned int flag,
    struct hinic3_dma_addr_align *mem_align)
{
    void *dev_hdl = NULL;
    struct hiudk_ops *ops = NULL;

    if (unlikely(!CHECK_UDK_DEV(udkdev))) {
        pr_err("udkdev is error! \n");
        return -EINVAL;
    }

    dev_hdl = GET_DEV_HDL_FROM_HIUDKHWDEV(udkdev);
    ops = GET_SDKOPS_FROM_HIUDKHWDEV(udkdev);
    if (likely((ops != NULL) && (ops->com_ops.hiudk_dma_zalloc_coherent_align != NULL))) {
        return ops->com_ops.hiudk_dma_zalloc_coherent_align(dev_hdl, size, align, flag, mem_align);
    }

    pr_err("ops is NULL! \n");
    return -EINVAL;
}

EXPORT_SYMBOL(hiudk_dma_zalloc_coherent_align);
